package com.fire.control.system.module.demo.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.fire.control.system.dto.app.AppDemoVo;
import com.fire.control.system.entity.Demo;
import com.fire.control.system.module.demo.dao.DemoMapper;
import com.fire.control.system.module.demo.service.IDemoService;
import com.fire.control.system.support.protocol.app.AppDemoRequest;
import com.fire.control.system.support.protocol.comman.DemoRequest;
import com.fire.control.system.support.protocol.comman.ProtocolSelector;
import com.fire.control.system.support.protocol.comman.ResponseJsonProtocol;
import com.fire.control.system.support.protocol.comman.ResponseProtocol;
import com.fire.control.system.support.util.ResultPageUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

@Service
public class DemoService implements IDemoService{

	@Autowired private DemoMapper demoMapper;
	@Autowired private ProtocolSelector protocolSelector;

	@Override
	public ResponseProtocol findAll(AppDemoRequest requestProtocol) {
		ResponseProtocol responseProtocol = protocolSelector.choose(requestProtocol);
		PageHelper.startPage(1, 3);
		List<AppDemoVo> list = demoMapper.findAll();
		responseProtocol.setData(ResultPageUtil.resultPage(new PageInfo<AppDemoVo>(list), list));
		return responseProtocol;
	}

	@Override
	public ResponseProtocol getAll(DemoRequest requestProtocol) {
		
		ResponseJsonProtocol jsonProtocol = new ResponseJsonProtocol();
		
		PageHelper.startPage(1, 2);
		List<Demo> list = demoMapper.getAll();
		
		PageInfo<Demo> pageInfo = new PageInfo<Demo>(list);
		Map<String, Object> map = ResultPageUtil.resultPage(pageInfo, list);
		jsonProtocol.setData(map);
		
		return jsonProtocol;
	}



}
